package com.fei.wechat.middlewar.service.impl.admin;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.fei.wechat.common.constant.EnumConstant.DeleteFlag;
import com.fei.wechat.common.model.vo.PagerVo;
import com.fei.wechat.common.util.ObjectUtils;
import com.fei.wechat.middlewar.api.admin.IRoleService;
import com.fei.wechat.middlewar.dao.admin.IRoleDao;
import com.fei.wechat.middlewar.mode.bo.admin.RoleBo;
import com.fei.wechat.middlewar.mode.entity.admin.Role;
import com.fei.wechat.middlewar.mode.vo.admin.RoleVo;

/**
 * 描述: 角色业务接口实现层
 * 版权: Copyright (c) 2018 
 * 公司: 飞翔科技 
 * 作者: 张进飞 
 * 版本: 1.0 
 * 创建日期: 2018年5月20日 
 * 创建时间: 下午10:38:07
 */
public class RoleServiceImpl implements IRoleService
{
    
    @Autowired
    private IRoleDao roleDao;
    
    @Override
    public Role getRolesByUserId(Long userId)
    {
        List<Role> roles = roleDao.getRolesByUserId(userId);
        if (null != roles && !roles.isEmpty())
        {
            return roles.get(0);
        }
        return null;
    }
    
    @Override
    public PagerVo<RoleVo> queryRoleVoPage(RoleBo roleBo) throws Exception
    {
        Map<String, Object> params = ObjectUtils.objectToMap(roleBo);
        params.put("deleteFlag", DeleteFlag._1.getFalg());
        int total = roleDao.countRolePage(params);
        PagerVo<RoleVo> pagerVo = new PagerVo<RoleVo>(roleBo.getCurrentPage(), roleBo.getPageSize(), total);
        int start = pagerVo.getStart();
        int size = pagerVo.getSize();
        params.put("start", start);
        params.put("size", size);
        List<RoleVo> roleVoList = roleDao.queryRoleVoPage(params);
        pagerVo.setData(roleVoList);
        return pagerVo;
    }
    
}
